import { defineStore } from 'pinia'

export const useLayoutStore = defineStore('layout', {
  state: () => ({
    activeMenu: '/dashboard', // 默认激活的菜单项
    isCollapse: false, // 菜单是否折叠
    // 菜单更新标注
    menuUpdate: false
  }),

  getters: {
    getActiveMenu: (state) => state.activeMenu,
    getIsCollapse: (state) => state.isCollapse,
    getMenuUpdate: (state) => state.menuUpdate
  },

  actions: {
    setActiveMenu(menu) {
      this.activeMenu = menu;
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    setCollapse(status) {
      this.isCollapse = status;
    },
    setMenuUpdate(status) {
      this.menuUpdate = status;
    }
  },

  // 开启持久化
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'erp-layout', // 存储的键名
        storage: localStorage // 使用localStorage存储
      }
    ]
  }
}) 